package com.promise.paging

import java.util.concurrent.Executor
import java.util.concurrent.Executors

/**
 * Created by CQNNJ-003 on 2018/6/8.
 */
open class DefaultServiceLocator : ServiceLocator{

    // thread pool used for network requests
    @Suppress("PrivatePropertyName")
    private val NETWORK_IO = Executors.newFixedThreadPool(5)

    private val api by lazy {
        Api.create()
    }
    override fun getRepository(): UserPostRepository {

        return UserPostRepository(
                redditApi = getRedditApi(),
            networkExecutor = getNetworkExecutor()
        )
    }

    override fun getNetworkExecutor(): Executor = NETWORK_IO

    override fun getRedditApi(): Api = api
}